/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.delaphone.flocash.web.action;

import com.delaphone.flocash.model.FBanks;
import com.delaphone.flocash.service.BankService;
import com.delaphone.flocash.web.util.Validate;
import com.opensymphony.xwork2.Action;
import java.util.Date;

/**
 *
 * @author tamdx
 */
public class AddBankAction extends BaseAction {
    private String bankName;
    private String accountNumber;
    private String accountName;
    private String swiftCode;
    private BankService bankService;
    private String message;

    public String index() {
        if (user == null) {
            return Action.ERROR;
        }
        return Action.INPUT;
    }

    public String addBanks() {
        if (user == null) {
            return Action.ERROR;
        }
        validateField();
        if(getActionErrors().size()>0){
            return Action.INPUT;
        }
        FBanks bank = new FBanks();
        bank.setUserId(user.getId());
        bank.setBankName(getBankName());
        bank.setSwiftCode(getSwiftCode());
        bank.setAccountName(getAccountName());
        bank.setAccountNumber(getAccountNumber());
        bank.setActive("no");
        bank.setVerifyReq(true);
        bank.setDateCreated(new Date());
        bankService.createBanks(bank);
        setMessage(getText("user.manage_card.addBank"));
        return Action.SUCCESS;
    }

    public void validateField(){
        if(Validate.isEmptyString(bankName)){
            addActionError(getText("user.manage_bank.bankName.null"));
        }else if(Validate.isEmptyString(accountNumber)){
            addActionError(getText("user.manage_bank.accountNumber.null"));
        }else if(Validate.isEmptyString(accountName)){
            addActionError(getText("user.manage_bank.accountName.null"));
        }else if(Validate.isEmptyString(swiftCode)){
            addActionError(getText("user.manage_bank.swiftCode.null"));
        }
    }

    public BankService getBankService() {
        return bankService;
    }

    public void setBankService(BankService bankService) {
        this.bankService = bankService;
    }

    
    public String getAccountName() {
        return accountName;
    }

    public void setAccountName(String accountName) {
        this.accountName = accountName;
    }

    public String getAccountNumber() {
        return accountNumber;
    }

    public void setAccountNumber(String accountNumber) {
        this.accountNumber = accountNumber;
    }

    public String getBankName() {
        return bankName;
    }

    public void setBankName(String bankName) {
        this.bankName = bankName;
    }

    public String getSwiftCode() {
        return swiftCode;
    }

    public void setSwiftCode(String swiftCode) {
        this.swiftCode = swiftCode;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    
    
}
